/* 
// 获取分类和标签的链接
let label = [];// 标签
$0.querySelectorAll("a").forEach((item) => {
    console.log('', item.href)
    let href = item.href;
    let hrefList = href.split('/');
    console.log('', hrefList)
    let targer = hrefList[4];
    console.log('', targer)
    // let decodeURIComponent = decodeURIComponent(targer);
    // console.log('', decodeURIComponent)
    if (targer) label.push(targer)
})

// let localStorageName = "class"
let localStorageName = "label"
let data = localStorage.getItem(localStorageName) || [];
label = data.concat(label)
localStorage.setItem(localStorageName, label)
console.log('', label)

 */



/* 
let className = ['chanId21', 'chanId1', 'chanId2', 'chanId22', 'chanId4', 'chanId15', 'chanId6', 'chanId5', 'chanId7', 'chanId8', 'chanId9', 'chanId20109', 'chanId10', 'chanId12', 'chanId20076chanId21-subCateId8', 'chanId21-subCateId73', 'chanId21-subCateId58', 'chanId21-subCateId78chanId1-subCateId38', 'chanId1-subCateId62', 'chanId1-subCateId201', 'chanId1-subCateId202', 'chanId1-subCateId20092', 'chanId1-subCateId20093chanId1-subCateId38', 'chanId1-subCateId62', 'chanId1-subCateId201', 'chanId1-subCateId202', 'chanId1-subCateId20092', 'chanId1-subCateId20093chanId2-subCateId5', 'chanId2-subCateId30', 'chanId2-subCateId206', 'chanId2-subCateId20099', 'chanId2-subCateId20100chanId22-subCateId18', 'chanId22-subCateId44', 'chanId22-subCateId64', 'chanId22-subCateId207', 'chanId22-subCateId20101chanId4-subCateId12', 'chanId4-subCateId16', 'chanId4-subCateId74', 'chanId4-subCateId130', 'chanId4-subCateId151', 'chanId4-subCateId153chanId6-subCateId54', 'chanId6-subCateId65', 'chanId6-subCateId80', 'chanId6-subCateId230', 'chanId6-subCateId231chanId5-subCateId22', 'chanId5-subCateId48', 'chanId5-subCateId220', 'chanId5-subCateId32', 'chanId5-subCateId222', 'chanId5-subCateId223', 'chanId5-subCateId224', 'chanId5-subCateId225', 'chanId5-subCateId226', 'chanId5-subCateId20094chanId7-subCateId7', 'chanId7-subCateId70', 'chanId7-subCateId240', 'chanId7-subCateId20102', 'chanId7-subCateId20103chanId9-subCateId21', 'chanId9-subCateId25', 'chanId9-subCateId68', 'chanId9-subCateId250', 'chanId9-subCateId251', 'chanId9-subCateId252', 'chanId9-subCateId253chanId20109-subCateId20110', 'chanId20109-subCateId20111', 'chanId20109-subCateId20112chanId12-subCateId60', 'chanId12-subCateId66', 'chanId12-subCateId281', 'chanId12-subCateId282']

let labelName = ['tag%E8%B1%AA%E9%97%A8', 'tag%E5%AD%A4%E5%84%BF', 'tag%E7%9B%97%E8%B4%BC', 'tag%E7%89%B9%E5%B7%A5', 'tag%E9%BB%91%E5%AE%A2', 'tag%E6%98%8E%E6%98%9F', 'tag%E7%89%B9%E7%A7%8D%E5%85%B5', 'tag%E6%9D%80%E6%89%8B', 'tag%E8%80%81%E5%B8%88', 'tag%E5%AD%A6%E7%94%9F', 'tag%E8%83%96%E5%AD%90', 'tag%E5%AE%A0%E7%89%A9', 'tag%E8%9C%80%E5%B1%B1', 'tag%E9%AD%94%E7%8E%8B%E9%99%84%E4%BD%93', 'tagLOL', 'tag%E5%BA%9F%E6%9D%90%E6%B5%81', 'tag%E6%8A%A4%E7%9F%AD', 'tag%E5%8D%A1%E7%89%87', 'tag%E6%89%8B%E6%B8%B8', 'tag%E6%B3%95%E5%B8%88', 'tag%E5%8C%BB%E7%94%9F', 'tag%E6%84%9F%E6%83%85', 'tag%E9%89%B4%E5%AE%9D', 'tag%E4%BA%A1%E7%81%B5', 'tag%E8%81%8C%E5%9C%BA', 'tag%E5%90%B8%E8%A1%80%E9%AC%BC', 'tag%E9%BE%99', 'tag%E8%A5%BF%E6%B8%B8', 'tag%E9%AC%BC%E6%80%AA', 'tag%E9%98%B5%E6%B3%95', 'tag%E9%AD%94%E5%85%BD', 'tag%E5%8B%87%E7%8C%9B', 'tag%E7%8E%84%E5%AD%A6', 'tag%E7%BE%A4%E7%A9%BF', 'tag%E4%B8%B9%E8%8D%AF', 'tag%E7%BB%83%E5%8A%9F%E6%B5%81', 'tag%E5%8F%AC%E5%94%A4%E6%B5%81', 'tag%E6%81%B6%E6%90%9E', 'tag%E7%88%86%E7%AC%91', 'tag%E8%BD%BB%E6%9D%BE', 'tag%E5%86%B7%E9%85%B7', 'tag%E8%85%B9%E9%BB%91', 'tag%E9%98%B3%E5%85%89', 'tag%E7%8B%A1%E7%8C%BE', 'tag%E6%9C%BA%E6%99%BA', 'tag%E7%8C%A5%E7%90%90', 'tag%E5%9A%A3%E5%BC%A0', 'tag%E6%B7%A1%E5%AE%9A', 'tag%E5%83%B5%E5%B0%B8', 'tag%E4%B8%A7%E5%B0%B8', 'tag%E7%9B%97%E5%A2%93', 'tag%E9%9A%8F%E8%BA%AB%E6%B5%81', 'tag%E8%BD%AF%E9%A5%AD%E6%B5%81', 'tag%E6%97%A0%E6%95%8C%E6%96%87', 'tag%E5%BC%82%E5%85%BD%E6%B5%81', 'tag%E7%B3%BB%E7%BB%9F%E6%B5%81', 'tag%E6%B4%AA%E8%8D%92%E6%B5%81', 'tag%E5%AD%A6%E9%99%A2%E6%B5%81', 'tag%E4%BD%8D%E9%9D%A2', 'tag%E9%93%81%E8%A1%80', 'tag%E5%8A%B1%E5%BF%97', 'tag%E5%9D%9A%E6%AF%85', 'tag%E5%8F%98%E8%BA%AB', 'tag%E5%BC%BA%E8%80%85%E5%9B%9E%E5%BD%92', 'tag%E8%B5%9A%E9%92%B1', 'tag%E4%BA%89%E9%9C%B8%E6%B5%81', 'tag%E7%A7%8D%E7%94%B0%E6%96%87', 'tag%E5%AE%85%E7%94%B7', 'tag%E6%97%A0%E9%99%90%E6%B5%81', 'tag%E6%8A%80%E6%9C%AF%E6%B5%81', 'tag%E5%87%A1%E4%BA%BA%E6%B5%81', 'tag%E7%83%AD%E8%A1%80', 'tag%E9%87%8D%E7%94%9F', 'tag%E7%A9%BF%E8%B6%8A'] */

// let ul = $('.all-img-list cf'); //  获取到有小说的ul标签
// let pageUl = $('.lbf-pagination-item-list'); // 获取到分页的ul标签
let className = JSON.parse(localStorage.getItem('class')); //  获取到分类的链接
let labelName = JSON.parse(localStorage.getItem('label')); // 获取到标签的链接

className.forEach((item) => {
    exeFn(item);
    // labelName.forEach((item_) => {
    //     exeFn(item + "-" + item_)
    // })
})
labelName.forEach((item) => {
    exeFn(item)
})

function exeFn(url) {
    fetch('https://www.qidian.com/finish/' + url + '/').then((res) => {
        return res.text();
    }).then((res) => {
        let dom = $(res)
        // debugger
        // console.log('', dom)

        let ul = dom.find('.all-img-list.cf'); //  获取到有小说的ul标签
        let pageUl = dom.find('.lbf-pagination-item-list'); // 获取到分页的ul标签
        if (ul.length > 0) {
            let li = $(ul).find('li');
            let wanBen = JSON.parse(localStorage.getItem('wanBen')) || {};
            if (li.length > 0) {
                li.each((index, item) => {
                    let info = $(item).find('.book-mid-info');
                    let name = info.find('h2').text().trim();
                    let href = info.find('h2 a')[0].href;
                    let author = info.find('.author a.name').text().trim();
                    let type = info.find('.author a')[1].innerText.trim();
                    let dec = info.find('.intro').text().trim();
                    let node = info.find('.update a').text().trim();
                    wanBen[name] = {
                        name, href, author, type, dec, node
                    }
                })
                // console.log('', wanBen)
                localStorage.setItem('wanBen', JSON.stringify(wanBen));
            }
        }
        if (pageUl.length > 0) {
            // console.log('', pageUl)
            let href = $(pageUl).find('li .lbf-pagination-next')[0].href;
            if (href.includes('www.qidian.com')) {
                exeFn(href)
            }
        }
    })
}

// exeFn('https://www.qidian.com/finish/' + 'chanId2' + '/')